/**
 * Looker  新闻整合系统
 * Author  :solosky
 * File    :WorkPoolFactory.java
 * Date    :May 9, 2009
 * Lisence : Apache License 2.0 
 */
package net.looker.work;

import java.util.HashMap;

/**
 * 线程池工厂
 * 可以使用不同的线程池
 * @author solosky
 *
 */
public class WorkerPoolFactory
{
	/**
	 * 当前的线程池
	 */
	private static HashMap <String,WorkerPool> poolMap = new HashMap<String,WorkerPool>();
	
	
	/**
	 * 创建一个线程池
	 * @param name
	 * @param maxWorker
	 * @return
	 */
	public static synchronized WorkerPool create(String name,int maxWorker)
	{
		if(poolMap.containsKey(name))
			return poolMap.get(name);
		else
		{
			WorkerPool w = new WorkerPool(maxWorker);
			poolMap.put(name, w);
			return w;
		}
	}
	
	/**
	 * 返回已经注册的线程池
	 * @param name
	 * @return
	 */
	public static WorkerPool get(String name)
	{
		if (poolMap.containsKey(name))
			return poolMap.get(name);
		else
			return null;
	}
}
